<?php defined('SYSPATH') or die('No direct script access.');
 
class javascript {

    public static function toJsArray($valueList) {
        return json_encode(array_values($valueList));
        /*
        $jsArray = "[";
        foreach ($valueList as $option) {
            $value = $option;
            // $option is array if $valueList comes from PDOStatement->fetchAll();
            if (is_array($option)) {
                $value = $option[0];
            }
            $jsArray .= "'" . self::escape($value) . "',";
        }
        if (strlen($jsArray) > 1) {
            $jsArray = substr($jsArray, 0, -1);
        }
        $jsArray .= "]";
        return $jsArray;
        */
    }

    public static function toAssociativeArray($valueList) {
        return json_encode($valueList);
        /*$jsArray = "{";
        foreach ($valueList as $key => $value) {
            $jsArray .= "'" . $key . "':'" . self::escape($value) . "',";
        }
        if (strlen($jsArray) > 1) {
            $jsArray = substr($jsArray, 0, -1);
        }
        $jsArray .= "}";
        return $jsArray;
         */
    }

    public static function escape($text) {
        $text = str_replace("\\", "\\\\", $text);
        $text = str_replace("'", "\\'", $text);
        return $text;
    }
}
?>
